define(
   [
      'dojo/_base/declare',
      'dojo/_base/lang',
      'dojo/json'
   ],
   function(declare, lang, JSON)
   {
      return declare([],
      {
         iconOk:           "/images/icons/fugue/icons/16x16/tick-circle.png",
         iconBad:          "/images/icons/fugue/icons/16x16/exclamation-red.png",
         iconInfo:         "/images/icons/fugue/icons/16x16/information.png",
         iconWaiting:      "/images/icons/fugue/icons/16x16/clock.png",
         iconWarning:      "/images/icons/fugue/icons/16x16/exclamation.png",
         iconUnauthorized: "/images/icons/fugue/icons/16x16/user--exclamation.png",
         constructor: function(args)
         {
            dojo.safeMixin(this, args);
            this.results = new Array();
            this.currentResult = null;
         },
         postscript: function(args)
         {
            this.inherited(arguments);
         },
         addResult: function(result)
         {
            if(!this.resultOkToPublish(result))
               return false;
      
            this.results.push(result);
            this.setCurrentResult(result);
      
            if(this.results.length >= this.maxResultsToSave)
               this.results.shift();
      
            return true;
         },
         checkError: function(pError)
         {
            if(pError.response.options.handleAs == "text")
            {
               var pObj = JSON.parse(pError.response.data);
               if(pObj)
                  this.addResult(pObj);
            }
            else
            {
               this.addResult(pError.response.data);
            }
         },
         setCurrentResult: function(result)
         {
            // Stub
         },
         formatMessageFromResult: function(result)
         {
            var image = "images/famfamfam/silk/16x16/help.png";
            switch(result.status)
            {
               case 'OK':              image = this.iconOk;      break;
               case 'Bad':             image = this.iconBad;     break;
               case 'Info':            image = this.iconInfo;    break;
               case 'Waiting':         image = this.iconWaiting; break;
               case 'Warning':         image = this.iconWarning; break;
               case 'Unauthorized':    image = this.iconUnauthorized; break;
            }
            var htmlImage = '<img src=\"'+image+'\"/ style=\"vertical-align:bottom\">';
            return '<div style="width:100%;height:100%;">' + htmlImage + ' '  + result.message + '</div>';
         },
         resultOkToPublish: function(result)
         {
            return true;
         }
      });
   }
);
